//
// Created by Administrator on 2023/1/18.
//

#ifndef RTOW_COLOR_H
#define RTOW_COLOR_H

#include "vec.h"

#include <iostream>

using color3 = vec3;

struct const_color
{
    static const color3& white(){
        static color3 white(1,1,1);
        return white;
    }
    static const color3& black(){
        static color3 black(0,0,0);
        return black;
    }
    static const color3& red(){
        static color3 red(1,0,0);
        return red;
    }
    static const color3& blue(){
        static color3 blue(0,0,1);
        return blue;
    }
    static const color3& green(){
        static color3 green(0,1,0);
        return green;
    }
};

inline color3 gamma_to_linear(color3 col){
    auto mi = 1 / 2.2;
    col.x = pow(col.x, mi);
    col.y = pow(col.y, mi);
    col.z = pow(col.z, mi);
    return col;
}

inline color3 linear_to_gamma(color3 col){
    col.x = pow(col.x, 2.2);
    col.y = pow(col.y, 2.2);
    col.z = pow(col.z, 2.2);
    return col;
}
//void write_color(std::ostream &out, color3 pixel_color, int scale) {
//    auto r = pixel_color.x;
//    auto g = pixel_color.y;
//    auto b = pixel_color.z;
//
//    // Divide the color by the number of samples and gamma-correct for gamma=2.0.
//    auto scale1 = 1.0 / scale;
//    r = sqrt(scale1 * r);
//    g = sqrt(scale1 * g);
//    b = sqrt(scale1 * b);
//
//    // Write the translated [0,255] value of each color component.
//    out << static_cast<int>(256 * clamp(r, 0.0, 0.999)) << ' '
//        << static_cast<int>(256 * clamp(g, 0.0, 0.999)) << ' '
//        << static_cast<int>(256 * clamp(b, 0.0, 0.999)) << '\n';
//}

#endif //RTOW_COLOR_H
